package com.cdp.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cdp.common.core.domain.AjaxResult;
import com.cdp.common.core.domain.entity.SysEfficiencyAgent;
import com.cdp.common.core.domain.entity.SysSwellingagent;
import com.cdp.common.core.domain.entity.SysWaterReducer;
import com.cdp.common.utils.StringUtils;
import com.cdp.system.dto.SandFinenessDTO;
import com.cdp.system.service.ISysEfficiencyAgentService;
import com.cdp.system.service.ISysSwellingagentService;
import com.cdp.system.service.ISysWaterReducerService;
import com.cdp.system.service.SysAgentTypeService;
import com.cdp.system.vo.AgentTypeVO;
import com.cdp.system.vo.SandFineneVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/system/sgentType")
public class SysAgentTypeController {


    @Autowired
    private SysAgentTypeService sysAgentTypeService;


    @Autowired
    private ISysEfficiencyAgentService sysEfficiencyAgentService;


    @Autowired
    private ISysWaterReducerService sysWaterReducerService;

    @Autowired
    private ISysSwellingagentService sysSwellingagentService;
    /**
     * 增效剂类型模糊查询
     *
     * @return
     */
    @PostMapping("listMistedAgentType")
    public AjaxResult listMistedAgentType(@RequestBody SandFinenessDTO sandFinenessDTO) {


        String name = sandFinenessDTO.getName();

        LambdaQueryWrapper<SysEfficiencyAgent> wrapper = new LambdaQueryWrapper<>();
        // 如果 name 不为空，则添加模糊查询条件
        if (!StringUtils.isEmpty(name)) {
            wrapper.like(SysEfficiencyAgent::getModel, name);
        }

        List<SysEfficiencyAgent> list = sysEfficiencyAgentService.list(wrapper);
        // 转换成 VO 对象，并映射字段
        List<SandFineneVO> sandFinenessVOList = list.stream()
                .map(s -> {
                    SandFineneVO vo = new SandFineneVO();
                    vo.setValue(s.getModel());
                    vo.setLabel(s.getModel());
                    return vo;
                })
                .collect(Collectors.toList());

        // 返回封装好的数据
        return AjaxResult.success(sandFinenessVOList);

    }

    /**
     * 减水剂类型模糊查询
     */

    @PostMapping("listWaterReducerTypeType")
    public AjaxResult listlistWaterReducerTypeType(@RequestBody SandFinenessDTO sandFinenessDTO)  {


        String name = sandFinenessDTO.getName();

        LambdaQueryWrapper<SysWaterReducer> wrapper = new LambdaQueryWrapper<>();
        // 如果 name 不为空，则添加模糊查询条件
        if (!StringUtils.isEmpty(name)) {
            wrapper.like(SysWaterReducer::getModel, name);
        }

        List<SysWaterReducer> list = sysWaterReducerService.list(wrapper);
        // 转换成 VO 对象，并映射字段
        List<SandFineneVO> sandFinenessVOList = list.stream()
                .map(s -> {
                    SandFineneVO vo = new SandFineneVO();
                    vo.setValue(s.getModel());
                    vo.setLabel(s.getModel());
                    return vo;
                })
                .collect(Collectors.toList());

        // 返回封装好的数据
        return AjaxResult.success(sandFinenessVOList);

    }


    /**
     * 膨胀类型模糊查询
     */

    @PostMapping("listSwellingagentType")
    public AjaxResult listSwellingagentType(@RequestBody SandFinenessDTO sandFinenessDTO)  {


        String name = sandFinenessDTO.getName();

        LambdaQueryWrapper<SysSwellingagent> wrapper = new LambdaQueryWrapper<>();
        // 如果 name 不为空，则添加模糊查询条件
        if (!StringUtils.isEmpty(name)) {
            wrapper.like(SysSwellingagent::getModel, name);
        }

        List<SysSwellingagent> list = sysSwellingagentService.list(wrapper);
        // 转换成 VO 对象，并映射字段
        List<SandFineneVO> sandFinenessVOList = list.stream()
                .map(s -> {
                    SandFineneVO vo = new SandFineneVO();
                    vo.setValue(s.getModel());
                    vo.setLabel(s.getModel());
                    return vo;
                })
                .collect(Collectors.toList());

        // 返回封装好的数据
        return AjaxResult.success(sandFinenessVOList);

    }













}
